package com.github.bridge.client.esign;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;

public class ESignAddress implements AddressSource {

    @Override
    public ForestAddress getAddress(ForestRequest forestRequest) {
        String scheme = SpringUtil.getApplicationContext().getEnvironment().getProperty("e.sign.scheme");
        String domain = SpringUtil.getApplicationContext().getEnvironment().getProperty("e.sign.domain");
        String portStr = SpringUtil.getApplicationContext().getEnvironment().getProperty("e.sign.port");
        if (StrUtil.isBlank(scheme) || StrUtil.isBlank(domain) || StrUtil.isBlank(portStr)) {
            throw new RuntimeException("e.sign.scheme or e.sign.domain or e.sign.port is blank");
        }
        return new ForestAddress(scheme, domain, Integer.parseInt(portStr));
    }
}
